﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Kaidou.Model;
using Kaidou.Persister;
using Kaidou.Util;
using Kaidou.Bll;
using System.Collections.Generic;
using System.Globalization;
public partial class seal_seal_report : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoginModel loginModel = (LoginModel)Session["loginModel"];

        if (loginModel == null)
        {
            Response.Redirect("../login.aspx");
        }
        if (!loginModel.isKumiaiin())
        {
            Response.Redirect("../menu.aspx");
        }

        if (loginModel.isKumiaiin() && sessioncontrol.control())
        {
            Response.Redirect("../control.aspx");
        }

        if (!IsPostBack)
        {
            string area = Resources.Resource.area;
            string[] areaArray = area.Split(',');
            for (int i = 0; i < areaArray.Length; i++)
            {
                ListItem item = new ListItem();
                item.Value = (i + 1) + "";
                item.Text = areaArray[i];
                HALL_PREF_CODE.Items.Insert(i + 1, item);
            }
            TRN_JUCHU_TANTO_NAME.Text = loginModel.OfficeTanto == null ? "" : loginModel.OfficeTanto;
        }
    }

    protected void login_confirm(object sender, EventArgs e)
    {
        try
        {
            Report rpt = new Report();
            LoginModel loginModel = (LoginModel)Session["loginModel"];

            TrnReporth model = new TrnReporth();
            //報告見出セット(TRN_Report_H)
            model.UnionCode = loginModel.Unioncode;
            model.BranchCode = (short)loginModel.Branchcode;
            model.ReportNo = "";
            model.ReportTantoName = TRN_JUCHU_TANTO_NAME.Text;
            model.EstCompClss = EST_COMP_CLSS1.Checked ? "0" : EST_COMP_CLSS2.Checked ? "1" : null;
            model.ConsCompName = CONS_COMP_NAME.Text;
            model.ConsCompTelno = CONS_COMP_TELNO.Text;
            model.ConsCompTelno = CONS_COMP_TELNO.Text;
            model.HallName = HALL_NAME.Text;
            model.HallPrefCode = short.Parse(HALL_PREF_CODE.Text);
            model.HallCity = HALL_CITY.Text;
            model.HallAddress = HALL_ADDRESS.Text;
            model.HallTel = HALL_TEL.Text;
            model.MachineName = MACHINE_NAME.Text;
            model.MachineQty = MACHINE_QTY.Text.Trim().Length == 0 ? -1 : int.Parse(MACHINE_QTY.Text);
            model.EstYear = EST_YEAR.Text;
            model.EstMonth = EST_MONTH.Text;
            model.EstDay = EST_DAY.Text;
            model.TraderRegNo1 = TRADER_REG_NO1.Text;
            model.TraderRegNo2 = TRADER_REG_NO2.Text;
            model.TraderRegNo = TRADER_REG_NO1.Text + TRADER_REG_NO2.Text;
            model.ChiefNo1 = CHIEF_NO1.Text;
            model.ChiefNo2 = CHIEF_NO2.Text;
            model.ChiefNo = CHIEF_NO1.Text + CHIEF_NO2.Text;
            model.ChiefName = CHIEF_NAME.Text;
            model.Worker1Name = WORKER1_NAME.Text;
            model.Worker2Name = WORKER2_NAME.Text;
            model.Worker3Name = WORKER3_NAME.Text;
            model.Worker4Name = WORKER4_NAME.Text;
            model.Worker5Name = WORKER5_NAME.Text;
            model.Worker6Name = WORKER6_NAME.Text;
            model.DupErrorFlg = "";
            model.DifReportFlg = "";
            model.OcrPassTxt = "";
            model.FaxErrorFlg = "";
            model.FaxocrText1 = "";
            model.FaxocrText2 = "";
            model.FaxocrText3 = "";
            model.FaxocrText4 = "";
            model.FaxocrText5 = "";
            model.FaxocrText6 = "";
            model.FaxocrText7 = "";
            model.FaxocrText8 = "";
            model.FaxocrText9 = "";
            model.FaxocrText10 = "";
            model.FaxocrText11 = "";
            model.FaxocrText12 = "";
            model.FaxocrText13 = "";
            rpt.setReportH(model);

            TrnReportd[] models = new TrnReportd[5];
            TrnReportd tmpmodel = null;
            TrnReportdId id = null;

            tmpmodel = new TrnReportd();
            id = new TrnReportdId();
            id.ReportNo = "";
            id.ReportRecNo = 1;
            tmpmodel.Id = id;
            tmpmodel.SealStrNo = SEAL_STR_NO1.Text;
            tmpmodel.SealEndNo = SEAL_END_NO1.Text;
            tmpmodel.MachineClss = MACHINE_CLSS11.Checked ? "1" : MACHINE_CLSS12.Checked ? "2" : null;
            models[0] = tmpmodel;

            tmpmodel = new TrnReportd();
            id = new TrnReportdId();
            id.ReportNo = "";
            id.ReportRecNo = 2;
            tmpmodel.Id = id;
            tmpmodel.SealStrNo = SEAL_STR_NO2.Text;
            tmpmodel.SealEndNo = SEAL_END_NO2.Text;
            tmpmodel.MachineClss = MACHINE_CLSS21.Checked ? "1" : MACHINE_CLSS22.Checked ? "2" : null;
            models[1] = tmpmodel;

            tmpmodel = new TrnReportd();
            id = new TrnReportdId();
            id.ReportNo = "";
            id.ReportRecNo = 3;
            tmpmodel.Id = id;
            tmpmodel.SealStrNo = SEAL_STR_NO3.Text;
            tmpmodel.SealEndNo = SEAL_END_NO3.Text;
            tmpmodel.MachineClss = MACHINE_CLSS31.Checked ? "1" : MACHINE_CLSS32.Checked ? "2" : null;
            models[2] = tmpmodel;

            tmpmodel = new TrnReportd();
            id = new TrnReportdId();
            id.ReportNo = "";
            id.ReportRecNo = 4;
            tmpmodel.Id = id;
            tmpmodel.SealStrNo = SEAL_STR_NO4.Text;
            tmpmodel.SealEndNo = SEAL_END_NO4.Text;
            tmpmodel.MachineClss = MACHINE_CLSS41.Checked ? "1" : MACHINE_CLSS42.Checked ? "2" : null;
            models[3] = tmpmodel;

            tmpmodel = new TrnReportd();
            id = new TrnReportdId();
            id.ReportNo = "";
            id.ReportRecNo = 5;
            tmpmodel.Id = id;
            tmpmodel.SealStrNo = SEAL_STR_NO5.Text;
            tmpmodel.SealEndNo = SEAL_END_NO5.Text;
            tmpmodel.MachineClss = MACHINE_CLSS51.Checked ? "1" : MACHINE_CLSS52.Checked ? "2" : null;
            models[4] = tmpmodel;

            rpt.setReportD(models);

            TRN_ReportManager validation = new TRN_ReportManager();
            List<string> errorCodeList = validation.checkInsertReport(rpt, Resources.Resource.ResourceManager, loginModel);
            msg.Text = ErrorCodeUtil.errorCodeListToHtml(errorCodeList);
            
            if (errorCodeList.Count == 0)
            {
                Session["report"] = rpt;
                Response.Redirect("seal_report_conf.aspx",false);
            }

        }catch(Exception e1){
            LogManager.error( "seal_report checckInsertReport error"+e1.Message+e1.StackTrace );
        }

    }
    
}
